package com.lechuang.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lechuang.common.model.BaseEntity;
import com.lechuang.common.request.PageRequest;
import com.lechuang.member.dto.MemberListDto;
import com.lechuang.member.dto.MemberRequestDto;
import com.lechuang.member.dto.SaveMemberDto;
import com.lechuang.member.entity.Member;
import com.lechuang.member.service.MemberService;
import com.lechuang.member.mapper.MemberMapper;
import com.lechuang.member.vo.MemberListVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import javax.sql.rowset.BaseRowSet;
import java.util.List;

/**
* @author apple
* @description 针对表【member(会员信息表)】的数据库操作Service实现
* @createDate 2024-06-22 11:43:19
*/
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member>
    implements MemberService{

    @Resource
    private MemberMapper memberMapper;

    @Override
    public Page<MemberListVo> pageList(PageRequest<MemberListDto> pageRequest) {
        Page<Member> page =new Page<>(pageRequest.getPageNum(),pageRequest.getPageSize());
        MemberListDto memberListDto = pageRequest.getQuery();
        return memberMapper.pageList(page,memberListDto);
    }

    @Override
    public MemberListVo queryById(MemberRequestDto memberRequestDto) {
        MemberListVo memberListVo = memberMapper.queryDetailById(memberRequestDto);
        return memberListVo;
    }

    @Override
    public Member queryByUserId(Long userId) {
        LambdaQueryWrapper<Member> lambdaQueryWrapper =new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Member::getUserId,userId);
        lambdaQueryWrapper.eq(BaseEntity::getStatus,BaseEntity.STATUS_NORMAL);
        return this.getOne(lambdaQueryWrapper,true);
    }

    @Override
    public void updateByUserId(Member member) {
        memberMapper.updateByUserId(member);
    }

    @Override
    public List<Member> queryByUserIds(List<Long> userIds) {
        LambdaQueryWrapper<Member> lambdaQueryWrapper =new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(Member::getUserId,userIds);
        lambdaQueryWrapper.eq(BaseEntity::getStatus, BaseEntity.STATUS_NORMAL);
        return this.list(lambdaQueryWrapper);
    }
}




